package com.xianbeiying.app.ckgl.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xianbeiying.app.ckgl.R;

import java.util.ArrayList;

/**
 * 历史数据适配
 */
public class PopWindowHistoryAdapter extends BaseAdapter{
    private Context context;
    private String [] strings;
    private int [] imgId;
    private ArrayList<Boolean> isBoolean;
    public ArrayList<Boolean> getIsBoolean() {
        return isBoolean;
    }
    public void setIsBoolean(ArrayList<Boolean> isBoolean) {
        this.isBoolean = isBoolean;
    }
    public PopWindowHistoryAdapter(Context context, String [] strings, int [] imgId) {
        this.context=context;
        this.strings = strings;
        this.imgId=imgId;
    }

    @Override
    public int getCount() {
        return strings.length;
    }

    @Override
    public Object getItem(int position) {
        return getItem(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.pop_window_history_item, parent, false);
            holder = new ViewHolder();
            holder.iv_pop_type=(ImageView) convertView.findViewById(R.id.iv_pop_type);
            holder.tv_pop_type=(TextView) convertView.findViewById(R.id.tv_pop_type);
            holder.iv_pop_img=(ImageView)convertView.findViewById(R.id.iv_pop_img);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.iv_pop_type.setImageResource(imgId[position]);
        holder.tv_pop_type.setText(strings[position]);
        if(getIsBoolean().get(position)){
            holder.iv_pop_img.setVisibility(View.VISIBLE);
        }else{
            holder.iv_pop_img.setVisibility(View.GONE);
        }
        return convertView;
    }
    private class ViewHolder{
       ImageView iv_pop_type;
       TextView tv_pop_type;
        ImageView iv_pop_img;
    }
}
